package com.applet.service.impl;

import com.applet.common.constant.StateConstant;
import com.applet.mapper.ClassifyMapper;
import com.applet.pojo.entity.Classify;
import com.applet.pojo.vo.ClassifyVO;
import com.applet.service.ClassifyService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author “XuShao”
 * @date 2024/12/16 21:00
 * @description
 */
@Service
public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify> implements ClassifyService {

    @Autowired
    private ClassifyMapper classifyMapper;

    @Override
    public List<ClassifyVO> getAll() {
        List<Classify> classifies = classifyMapper.selectList(new LambdaQueryWrapper<Classify>().eq(Classify::getDeleted, StateConstant.ENABLE));

        List<ClassifyVO> classifyVOS = new ArrayList<>();

        for (Classify item : classifies) {
            ClassifyVO classifyVO = new ClassifyVO(item.getId(), item.getTitle(), item.getType());
            classifyVOS.add(classifyVO);
        }

        return classifyVOS;
    }

    @Override
    public List<ClassifyVO> getType(Short type) {
        List<Classify> classifies = classifyMapper.selectList(new LambdaQueryWrapper<Classify>()
                .eq(Classify::getDeleted, StateConstant.ENABLE)
                .eq(Classify::getType, type));

        List<ClassifyVO> classifyVOS = new ArrayList<>();

        for (Classify item : classifies) {
            ClassifyVO classifyVO = new ClassifyVO(item.getId(), item.getTitle(), item.getType());
            classifyVOS.add(classifyVO);
        }

        return classifyVOS;
    }
}
